<?php
/**
 * 唯一入口文件
 */
require_once 'Include/Init.php';

$router_path = isset($_REQUEST['router_path']) ? trim($_REQUEST['router_path']) : '';
$router_path = trim($router_path, '/');
$path = explode('/', $router_path);

if (isset($path[0]) && !is_dir(ROOT_DIR . 'Controllers/' . $path[0])){
	array_unshift($path, 'Index');
}
$package 	= ucfirst(isset($path[0]) && $path[0] ? trim($path[0]) : 'Index');
$controller	= ucfirst(isset($path[1]) && $path[1] ? trim($path[1]) : 'Index');
$method		= isset($path[2]) && $path[2] ? trim($path[2]) : '_default';
define('APP_NAME', $package);

$filename = ROOT_DIR . 'Controllers/' . $package . '/' . $controller . '.php';

if (!file_exists($filename)){
	header("Location: 404.html");
}

$GLOBALS['package'] = $package;
$GLOBALS['controller'] = $controller;
$GLOBALS['method'] = $method;
$GLOBALS['router'] = $router_path;
$GLOBALS['short_router'] = "/$package/$controller/";

View::assign('package', $package);
View::assign('controller', $controller);
View::assign('method', $method);
View::assign('router', "/$router_path/");
View::assign('short_router', "/$package/$controller/");

$ctr_handle = new $controller();

$ctr_handle->$method();
